<?php

namespace addons\TinyShare\merchant\controllers;

use yii\data\Pagination;
use common\enums\StatusEnum;
use common\traits\MerchantCurd;
use common\models\base\SearchModel;
use addons\TinyShare\common\models\ShareContent;

class ShareTrashController extends BaseController
{
	use MerchantCurd;
	
	public $modelClass = ShareContent::class;
	
	public function actionIndex()
    {
        $data = ShareContent::find()
            ->where(['<', 'status', StatusEnum::DISABLED])
            ->andFilterWhere(['merchant_id' => $this->getMerchantId()]);
        $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
        $models = $data->offset($pages->offset)
            ->orderBy('id desc')
            ->limit($pages->limit)
            ->all();

        return $this->render($this->action->id, [
            'models' => $models,
            'pages' => $pages
        ]);
    }
	
	/**
     * 还原
     *
     * @param $id
     * @return mixed
     */
    public function actionShow($id)
    {
        $model = $this->findModel($id);
        $model->status = StatusEnum::ENABLED;
        if ($model->save()) {
            return $this->message("还原成功", $this->redirect(['index']));
        }

        return $this->message("还原失败", $this->redirect(['index']), 'error');
    }
}
